<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>菜单添加</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  <link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />
  <style type="text/css">
    .site-doc-icon li{
      display: inline-block;
      vertical-align: middle;
      width: 127px;
      line-height: 25px;
      padding: 20px 0;
      margin-right: -1px;
      margin-bottom: -1px;
      border: 1px solid #e2e2e2;
      font-size: 14px;
      text-align: center;
      color: #666;
      transition: all .3s;
      -webkit-transition: all .3s;
    }
  </style>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
  <input type="hidden" id="flag" class="flag" name="flag" value="${flage}" />
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-block">
      <input type="text"  class="layui-input userName" <#if baseUser.userName?? >readonly</#if> id="userName" name="userName" value="${baseUser.username}" placeholder="请输入用户名" lay-verify="required">
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">登录名</label>
    <div class="layui-input-block">
      <input type="text"  class="layui-input userid" <#if baseUser.userid?? >readonly</#if> id="userid" name="userid" value="${baseUser.userid}" placeholder="请输入登录名" lay-verify="required">
    </div>
  </div>

  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">头像</label>
    <div class="layui-input-block">
      <div class="famous-upload-pic">
        <img  <#if baseUser.headlogo?if_exists  >src="${baseUser.headlogo}"<#else>src="${s.base}/image/head_defalut.png"</#if> class="upload-avatar" id="upload-avatar"/>
        <input type="file" name="myfiles" class="upload" id="myFile" onchange="ajaxFileUploads('myFile','headLogo','upload-avatar')">
        <input type="hidden" class="headLogo" id="headLogo" <#if baseUser.headlogo?if_exists  > value="${baseUser.headlogo}"  <#else> value="/image/head_defalut.png" </#if> />
      </div>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-block">
      <input type="password" class="layui-input password"id="password" name="password" value="${baseUser.userpassword}" placeholder="请输入密码" maxlength="20" lay-verify="required" placeholder="请输入菜单连接">
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">组织</label>
    <div class="layui-input-block">
      <select name="departid" class="departid" lay-verify="required" lay-filter="departid">
        <#list baseDepartsList as baseDepart>
          <option <#if baseUser.departid == baseDepart.departid >selected</#if> value="${baseDepart.departid}">${baseDepart.departname}</option>
        </#list>
      </select>
    </div>
  </div>

  <div class="layui-form-item layui-row layui-col-xs12">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="btnSubmit">确定</button>
      <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary closeLay">取消</button>
    </div>
  </div>
</form>
<ul class="site-doc-icon icons layui-row">
</ul>
<script src="${s.base}/js/base/jquery-3.2.0.min.js"></script>
<script type="text/javascript" src="${s.base}/js/base/ajaxfileupload.js"></script>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form','layer'],function(){
        var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        form.on("submit(btnSubmit)",function(data){
            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            // 实际使用时的提交信息
            $.post("/baseUser/UpdateOrAddEntity",{
                userid : $(".userid").val(),
                headLogo : $(".headLogo").val(),
                username : $(".userName").val(),
                userpassword : $(".password").val(),
                departid : data.field.departid,
                headLogo:$(".headLogo").val(),
                flag : $(".flag").val(),
            },function(result){
                if(1==result.returnInfo.state){
                    top.layer.close(index);
                    top.layer.msg("操作成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }else{
                    top.layer.msg(result.returnInfo.errorMsg);
                }
            },"json")
            return false;
        });

        function ajaxFileUploads(){
            //开始上传文件时显示一个图片,文件上传完成将图片隐藏
            //$("#loading").ajaxStart(function(){$(this).show();}).ajaxComplete(function(){$(this).hide();});
            //执行上传文件操作的函数
            $.ajaxFileUpload({
                //处理文件上传操作的服务器端地址(可以传参数,已亲测可用)
                url:'/file/fileUpload?uname=123',
                secureuri:false,                           //是否启用安全提交,默认为false
                fileElementId:'myFile',               //文件选择框的id属性
                dataType:'text',                           //服务器返回的格式,可以是json或xml等
                success:function(data, status){            //服务器响应成功时的处理函数
                    data = data.replace(/<pre.*?>/g, '');  //ajaxFileUpload会对服务器响应回来的text内容加上<pre style="....">text</pre>前后缀
                    data = data.replace(/<PRE.*?>/g, '');
                    data = data.replace("<PRE>", '');
                    data = data.replace("</PRE>", '');
                    data = data.replace("<pre>", '');
                    data = data.replace("</pre>", '');
                    debugger;//本例中设定上传文件完毕后,服务端会返回给前台[0`filepath]
                    if(data.substring(0, 1) == 0){         //0表示上传成功(后跟上传后的文件路径),1表示失败(后跟失败描述)
                        top.layer.msg(data.substring(2));
                        $("#upload-avatar").attr("src", data.substring(2));
                        $("#headLogo").attr("src", data.substring(2));

                    }else{
                        top.layer.msg('图片上传失败，请重试！！');
                    }
                },
                error:function(data, status, e){ //服务器响应失败时的处理函数
                    top.layer.msg('图片上传失败，请重试！！');
                }
            });
        }

    })
</script>

</body>
</html>